package com.dicsystems.myrec.dao;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.dicsystems.myrec.Common;
import com.dicsystems.myrec.DatabaseHelper;
import com.dicsystems.myrec.dto.Holiday;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class HolidayDao {

	private Context me;
	private Common co = new Common();
	private SQLiteDatabase db;
	private final String TABLE = "holiday";
	private final int ID = 0;
	private final int NAME = 1;

	public HolidayDao(Context context) {
		this.me = context;
		co.me = context;
	}

	public void open() {
		db = new DatabaseHelper(me).getReadableDatabase();
	}

	public void close() {
		db.close();
	}

	public List<Holiday> select(Calendar start_date, Calendar end_date) {
		List<Holiday> holidays = new ArrayList<Holiday>();
		Cursor cursor = db.query(TABLE, null, "_id BETWEEN ? AND ?", new String[] {co.date(start_date), co.date(end_date)}, null, null, "_id");
		if(cursor.moveToFirst()) {
			do {
				Holiday holiday = new Holiday();
				holiday.id = cursor.getString(ID);
				holiday.name = cursor.getString(NAME);
				holidays.add(holiday);
			} while(cursor.moveToNext());
		}
		cursor.close();
		return holidays;
	}
}
